home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / C / StartDPK / StartDPK.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-09  |  3.7 KB  |  149 lines

  1. /* Name:      StartDPK
  2. ** Template:  StartDPK <TaskFile> [-p <Name>] <Arg1> <Arg2> ...
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions (c) 1997.  All rights reserved.
  5. ** Date:      October 1997
  6. ** Docs:      This program is intended to allow multi-platform capabilities by
  7. **            doing things like opening the kernel.  For example the following
  8. **            code would not work on a Mac even if it is 68000 code:
  9. **
  10. **              move.l $4.w,a6
  11. **              ...
  12. **              CALL   OpenLibrary
  13. **
  14. **            To fix this problem we put this machine-specific code in a task
  15. **            launcher (StartDPK) and pass the DPKBase onto the task.  Alakazam,
  16. **            multiple platform capabilities!
  17. **
  18. ** PROBLEMS:  Programs written in E cannot cope with this as far as I know :-(.
  19. */
  20.  
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <proto/dpkernel.h>
  24. #include <system/tasks.h>
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30.  
  31. extern struct ExecBase *SysBase;
  32.  
  33. /*** Proto-types ***/
  34.  
  35. void PrintUsage(void);
  36. void Launch(void);
  37. __asm LaunchTask(register __a0 struct Segment *);
  38.  
  39. /*** Program variables ***/
  40.  
  41. BYTE *TaskFile = NULL;
  42. BYTE *Prefs    = NULL;
  43. struct Segment *Segment = NULL;
  44. struct StartUp *StartUp = NULL;
  45. struct FileName file = { ID_FILENAME, NULL };
  46.  
  47. /************************************************************************************
  48. **
  49. ** ArgV: 0 = StartDPK
  50. **       1 = Task File
  51. **       2 = -p
  52. **       3 = Prefs
  53. **       4 = Arguments
  54. **           ...
  55. */
  56.  
  57. LONG main(LONG argc, BYTE *argv[])
  58. {
  59.   if ((argc < 2) OR (argv[1][0] IS '?')) {
  60.      PrintUsage();
  61.      return(NULL);
  62.   }
  63.  
  64.   /*printf("Amount of arguments: %d\n",argc);*/
  65.   printf("Loading: %s\n",argv[1]);
  66.  
  67.   file.Name = argv[1];   /* Task is always specified in argument 1 */
  68.  
  69.   /* Check for preferences */
  70.  
  71.   if (argc > 3) {
  72.      if ((argv[2][0] IS '-') AND (toupper(argv[2][1]) IS 'P')) {
  73.         Prefs = argv[3];
  74.      }
  75.   }
  76.  
  77.   /* Open the library, launch the program and then
  78.   ** shut down before exiting.
  79.   */
  80.  
  81.   if (DPKBase = (struct DPKBase *)OpenLibrary("GMS:libs/dpkernel.library",0)) {
  82.  
  83.      Launch();
  84.  
  85.      CloseDPK();
  86.   }
  87.  
  88.   return(NULL);
  89. }
  90.  
  91. /***********************************************************************************/
  92.  
  93. void PrintUsage(void)
  94. {
  95.   printf("\nSTARTDPK\n");
  96.   printf("--------\n");
  97.   printf("This program will launch DPK tasks for you, and in future will\n");
  98.   printf("be required for setting up programs that have been compiled on other\n");
  99.   printf("platforms.\n\n");
  100.   printf("To use it, just type:\n\n");
  101.   printf("  1> StartDPK <file> [-p prefsname] [Arg1] [Arg2] [Arg3] ...\n\n");
  102.   printf("Example:\n");
  103.   printf("  1> StartDPK DPK:demos/Redimension -p Settings1\n\n");
  104. }
  105.  
  106. /************************************************************************************
  107. **
  108. **
  109. **
  110. */
  111.  
  112. #define PREFSLEN 10     /* GMS:Prefs/ */
  113.  
  114. void Launch(void)
  115. {
  116.   struct DPKTask *Task;
  117.   WORD i,j;
  118.  
  119.   if (Task = FindDPKTask()) {
  120.      if (Prefs) {
  121.         if (Task->Preferences = AllocMemBlock(PREFSLEN+strlen(Prefs)+2,MEM_DATA)) {
  122.            strcpy(Task->Preferences,"GMS:Prefs/");
  123.            j = NULL;
  124.            i = PREFSLEN;
  125.            while (Prefs[j] != NULL) {
  126.               Task->Preferences[i++] = Prefs[j++];
  127.            }
  128.            Task->Preferences[i++] = '/';
  129.            Task->Preferences[i]   = NULL;
  130.  
  131.            printf("Preferences: %s\n",Task->Preferences);
  132.         }
  133.      }
  134.  
  135.      if (Segment = Load(&file,ID_SEGMENT)) {
  136.         LaunchTask(Segment);
  137.         Free(Segment);
  138.      }
  139.      else printf("Sorry, the file that you specified does not exist.\n");
  140.  
  141.      if (Prefs) {
  142.         FreeMemBlock(Task->Preferences);
  143.         Task->Preferences = NULL;
  144.      }
  145.   }
  146.   else printf("Could not find DPK task, error.\n");
  147. }
  148.  
  149.